<?php
namespace app\wechat\controller;

class MemberRoleInfo extends Common
{
    // 设置页面
    public function save_role_info() {
        $id = session('member_id');
        $param['member_id'] = $id;
        $param['type'] = 3;

        $data = call_interface('get_member_role_info', $param);
        $member_info = $data['data'];
        // 如果头像和昵称不存在则使用微信头像和昵称
        isset($member_info['nickname']) && $member_info['nickname'] ? $member_info['nickname'] : $member_info['nickname'] = session('nickname');
        isset($member_info['headimgurl']) && $member_info['headimgurl'] ? $member_info['headimgurl'] : $member_info['headimgurl'] = session('headimgurl');
        $this->assign('member_info', $member_info);
        $this->assign('type', $param['type']);
        return view();
    }

    // 设置用户信息
    public function save_member_role_info() {
        $member_id = session('member_id');
        if (request()->isPost()) {
            $param = [
                'member_id' => $member_id,
                'type' => 3,
                'field' => input('param.field'),
                'value' => input('param.value')
            ];
            if ($param['field'] == 'birthday') {
                $param['value'] = strtotime($param['value']);
            }
            //dump($param);
            $data = call_interface('save_role_info', $param);
            if ($data['code'] == 200) {
                $data['url'] = url('save_role_info', ['type' => input('param.type')]);
            }
            return json($data);
        } else {
            $param = [
                'member_id' => $member_id,
                'type' => 3,
                'field' => input('param.field'),
                'value' => input('param.value')
            ];
            $data = call_interface('get_field_info', $param);
            $this->assign('type', $param['type']);
            $this->assign('value', $data['data']['value']);
            $this->assign('field', $param['field']);
            return view();
        }
    }

    // 实名认证
    public function certification() {
        $member_id = session('member_id');

        $param = [
            'member_id' => $member_id,
        ];
        $data = call_interface('certification_info', $param);
        $this->assign('data', $data['data']);
        return view();
    }
}
